package cn.edu.scau.cmi.maikejian.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class SortObjectAdapter implements Sort{
	private Adaptee adaptee = new Adaptee();
	@Override
	public List<Student> sortStudents(List<Student> students) {
		List<Integer> intlist = new ArrayList<Integer>();
		List<Student> newStudentList = new ArrayList<Student>();
		Map<Integer, String> studentMap = new HashMap<>();
		Iterator<Student> studentIter = students.iterator();
		while (studentIter.hasNext())
		{
			Student student = studentIter.next();
			intlist.add(student.getId());
			studentMap.put(student.getId(), student.getName());
		}
		intlist = adaptee.sortInt(intlist);
		for(Integer id:intlist)
		{
			newStudentList.add(new Student(id, studentMap.get(id)));
		}

		return newStudentList;
	}

}